package com.directv.z8training.ex6;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

/**
 * @author HieuLT8
 *
 */
public class RunDemo {

	public static void main(String[] args) {
		HashSet<Person> setPerson = new HashSet<Person>();
		Person p1 = new Person(1, "An", "HCM", 20);
		Person p2 = new Person(2, "Binh", "HCM", 5);
		Person p3 = new Person(3, "Tuan", "HCM", 6);
		Person p4 = new Person(4, "Chau", "HCM", 11);
		Person p5 = new Person(6, "Thai", "HCM", 20);
		Person p6 = new Person(5, "Dung", "HCM", 21);
		Person p7 = new Person(12, "Hoang", "HCM", 22);
		Person p8 = new Person(8, "Kiet", "HCM", 23);
		Person p9 = new Person(9, "Lan", "HCM", 24);
		Person p10 = new Person(10, "Tien", "HCM", 5);
		Person p11 = new Person(11, "Bich", "HCM", 6);
		Person p12 = new Person(7, "Minh", "HCM", 10);
		setPerson.add(p1);
		setPerson.add(p2);
		setPerson.add(p3);
		setPerson.add(p4);
		setPerson.add(p5);
		setPerson.add(p6);
		setPerson.add(p7);
		setPerson.add(p8);
		setPerson.add(p9);
		setPerson.add(p10);
		setPerson.add(p11);
		setPerson.add(p12);
		List<Person> listPerson = new ArrayList<Person>(setPerson);
		Collections.sort(listPerson, new CompareName());
		System.out.println("Sort Name by Comparator");
		for (Person p : listPerson) {
			System.out.println("Name: " + p.getName() + " " + "Age: "
					+ p.getAge());
		}
		Collections.sort(listPerson);
		System.out.println("Sort Name by Comparable");
		for (Person p : listPerson) {
			System.out.println("Name: " + p.getName() + " " + "Age: "
					+ p.getAge());
		}
		Collections.sort(listPerson, new SortTop());
		System.out.println("Top 10");
		for (int i = 0; i < 10; i++) {
			
			System.out.println("Name: " + listPerson.get(i).getName() + " " + "Age: "
					+ listPerson.get(i).getAge());
		}
		System.out.println("Top 10 Age over 10");
		Collections.sort(listPerson, new CompareAge());
		for (int i = 0; i < 10; i++) {
			if(listPerson.get(i).getAge() > 10)
			System.out.println("Name: " + listPerson.get(i).getName() + " " + "Age: "
					+ listPerson.get(i).getAge());
		}
	}

}
